/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.factory;

import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

/**
 * 
 * @author Roy Description: 日志工厂
 * 
 */
public class LogFactory {
	private static LogFactory instance;
	private static Logger logger;
	private static FileHandler handler;
	private String logName = "server";

	// 私有构造器
	private LogFactory() {
		try {// 获得日志器
			logger = Logger.getLogger("LogFactory.log");
			handler = new FileHandler("log/" + logName + "%g.log", 1000, 5,true);
			handler.setFormatter(new SimpleFormatter());// 使用txt文本格式
			// 把文件处理器添加到logger
			logger.addHandler(handler);
			// 设置级别
			// logger.severe(msg)
			// logger.info(msg);
			// logger.warning(msg);
			// logger.severe();
			logger.setLevel(Level.INFO);// 默认级别,最好统一规定
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	public static LogFactory getInstance() {
		synchronized ("k") {// 同步处理
			if (instance == null) {// 只有一个线程进来创建实例
				instance = new LogFactory();
			}
		}
		return instance;
	}// 通过对象获得当前的logger

	public Logger getLogger() {
		return this.logger;
	}

	// 方法重载
	public Logger getLogger(String logName) {
		this.logName = logName;
		return this.logger;
	}

}
